#include <bits/stdc++.h>
using namespace std;

typedef long long LL;

const LL MOD = 998244353;
const int N = 1e6 + 5;

LL bin(LL a, LL b, LL p = MOD)
{
    LL res = 1;
    for (a %= p; b; b >>= 1, a = a * a % p)
        if (b & 1)
            res = res * a % p;
    return res;
}

LL inv(LL a, LL p = MOD) { return bin(a, p - 2, p); }

int n;

vector<int> k[N];

int num[N];

inline int hasntExcept(int x)
{
    return n - (num[x]);
}

int main(int argc, char const *argv[])
{
    // cout << 7LL * inv(8) % MOD << endl;

    scanf("%d", &n);
    for (int i = 1; i <= n; ++i)
    {
        int kx;
        scanf("%d", &kx);
        k[i].resize(kx);
        for (int j = 0; j < kx; ++j)
        {
            scanf("%d", &k[i][j]);
            ++num[k[i][j]];
        }
    }
    LL ans = 0, basep = inv(n) * inv(n) % MOD;
    // printf("%d %d\n", num[1], num[2]);
    for (int i = 1; i <= n; ++i)
    {
        LL p = basep * inv(k[i].size()) % MOD;
        for (int x : k[i])
        {
            
            ans += p * hasntExcept(x) % MOD;
            // printf("%d %lld\n", hasntExcept(x), ans);
        }
    }

    // ans %= MOD;
    // ans = (1 + MOD - ans % MOD) % MOD;
    ans = ((1 - ans) % MOD + MOD) % MOD;
    printf("%lld\n", ans);

    return 0;
}
